#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import jsonify, request
from flask_restful import Resource
from utility.odoo_manager import OdooManager  # 操作odoo的单例
from utility.error_code import error_code  # 异常代码
from utility.message_manager import MessageBusManager
from event import event_type
from command import command
import logging
from utility import tools

FORMAT = "%(asctime)s %(thread)d %(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)


class OperationRecNewAPI(Resource):
    """
    新增剖宫产手术记录单
    :request: post
    :param archivesId: 档案ID
    :param ssjbxx: 手术基本信息
            {
                "ssSj": 手术时
                "csssSj": 出手术室时间
                "ssmc": 手术名称
                "sqzd": 术前诊断
                "sszz": 手术指征
                "shzd": 术后诊断
                "ssz": 手术者
                    {
                        "zdysCode": 主刀医生编码
                        "zdysName": 主刀医生姓名
                        "yzCode": 一助编码
                        "yzName": 一助姓名
                        "ezCode": 二助编码
                        "ezName": 二助姓名
                        "xshsCode": 洗手护士编码
                        "xshsName": 洗手护士姓名
                        "xhhsCode": 巡回护士编码
                        "xhhsName": 巡回护士姓名
                        "mzsCode": 麻醉师编码
                        "mzsName": 麻醉师姓名
                        "jszCode": 接生者编码
                        "jszName": 接生者姓名
                    }
                "mzfs": 麻醉方式
                "mzxg": 麻醉效果
            }
    :param sqjcyzb: 术前检查与准备
            {
                "sqtx": 术前胎心
                "tw": 体位
            }
    :param ssgc: 手术过程
            {
                "ssqklx": 手术切口类型
                "ssqkcd": 手术切口长度
                "ybhqccd": 原疤痕切除长度
                "fmwz": 腹膜位置
                "kfsfsl": 开腹是否顺利
                "tczgwz": 探查子宫位置
                "tczcfj": 探查左侧附件
                "tcycfj": 探查右侧附件
                "zgxdxc": 子宫下段形成
                "sfzl": 是否粘连
                "dkpgfmfz": 打开膀胱腹膜反折
                "zgqklx": 子宫切口类型
                "zgqkcd": 子宫切口长度
                "qksfsl": 切口是否撕裂
                "ysxz": 羊水性状
                "ysl": 羊水量
                "teYsxz": 胎二羊水性状
                "teYsl": 胎二羊水量
            }
    :param xse: 新生儿
            [
                {
                    "id": id
                    "sex": 性别
                    "Weigth": 体重
                    "Length": 身长
                    "mcsj": 娩出时间
                    "tpblfs": 胎盘剥离方式
                    "sfsq": 是否手取
                    "qchsfwz": 取出后是否完整
                    "tpLength": 胎盘长
                    "tpWidth": 胎盘宽
                    "tpHeigth": 胎盘高
                    "tpWeigth": 胎盘重
                    "tpfz": 胎盘附着部位
                    "qdLength": 脐带长度
                    "qrjzs": 脐绕颈周数
                    "ycqk": 异常情况
                }
            ]
    :param fh: 缝合
            {
                "zgfh": 子宫缝合
                "gffh": 关腹缝合
                "fmfh": 缝合-腹膜
                "jmfh": 缝合筋膜
                "fhpxzf": 缝合皮下脂肪
                "fhpf": 缝合皮肤
            }
    :param szyy: 术中用药
            {
                "szsfyy": 术中是否用药
                "gssyl": 宫缩素用量
            }
    :param gs: 宫缩
            {
                "szcx": 术中出血
                "sx": 输血
                "sy": 输液
                "sznl": 术中尿量
                "gs": 宫缩
            }
    :param tsqk: 特殊情况
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            # 参数校验
            req_params = ['archivesId','ssjbxx','sqjcyzb','ssgc','te','fh','szyy','gs','qt']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            # 产妇情况
            cfqk_data_ = {
               'archives_id': params.get('archivesId'),
               # 'cf_yz_week': tools.nullablea_dict(params.get('cfqk'), 'yzZ'),
               # 'cf_yz_day': tools.nullablea_dict(params.get('cfqk'), 'yzT'),
               # 'cf_yc': tools.nullablea_dict(params.get('cfqk'), 'yc'),
               'cf_ts': params.get('ts'),
               'cf_cb': tools.nullablea_dict(params.get('cfqk'), 'cb'),
               'cf_hbz': tools.nullablea_dict(params.get('cfqk'), 'hbz'),
               'cf_hbz_other': tools.nullablea_dict(params.get('cfqk'), 'hbzQt'),
               'cf_bfz': tools.nullablea_dict(params.get('cfqk'), 'bfz'),
               'cf_ccsyc': tools.nullablea_dict(params.get('cfqk'), 'ccsyc'),
               'cf_wzycf': tools.nullablea_dict(params.get('cfqk'), 'wzycf'),

               'ss_create_time': tools.nullablea_dict(params.get('ssjbxx'), 'ssSj'),
               'ss_end_time': tools.nullablea_dict(params.get('ssjbxx'), 'csssSj'),
               'ss_name': tools.nullablea_dict(params.get('ssjbxx'), 'ssmc'),
               'ss_sqzd': tools.nullablea_dict(params.get('ssjbxx'), 'sqzd'),
               'ss_cf_zz': tools.nullablea_dict(params.get('ssjbxx'), 'sszz'),
               'ss_shzd': tools.nullablea_dict(params.get('ssjbxx'), 'shzd'),
               'ss_zd': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['zdysCode'],
               'ss_yz': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['yzCode'],
               'ss_ez': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['ezCode'],
               'ss_sshs': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['xshsCode'],
               'ss_mzfs': tools.nullablea_dict(params.get('ssjbxx'), 'mzfs'),
               'ss_mzxg': tools.nullablea_dict(params.get('ssjbxx'), 'mzxg'),
               'ss_mzs': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['mzsCode'],
               'ss_tsz': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['jszCode'],


               'ss_sqtx': tools.nullablea_dict(params.get('sqjcyzb'), 'sqtx'),
               'ss_tw': tools.nullablea_dict(params.get('sqjcyzb'), 'tw'),
               'ss_xd': tools.nullablea_dict(params.get('sqjcyzb'), 'xd'),

               'ss_qk': tools.nullablea_dict(params.get('ssgc'), 'ssqklx'),
               'ss_ysbqc': tools.nullablea_dict(params.get('ssgc'), 'ybhqccd'),
               'ss_fm1': tools.nullablea_dict(params.get('ssgc'), 'fmwz'),
               'ss_kf': tools.nullablea_dict(params.get('ssgc'), 'kfsfsl'),
               'ss_zx': tools.nullablea_dict(params.get('ssgc'), 'tczgwz'),
               'ss_sfjzc': tools.nullablea_dict(params.get('ssgc'), 'tczcfj'),
               'ss_sfjyc': tools.nullablea_dict(params.get('ssgc'), 'tcycfj'),
               'ss_zgxdxc': tools.nullablea_dict(params.get('ssgc'), 'zgxdxc'),
               'ss_nl': tools.nullablea_dict(params.get('ssgc'), 'sfzl'),
               'ss_dkpgfm': tools.nullablea_dict(params.get('ssgc'), 'dkpgfmfz'),
               'ss_zgqk': tools.nullablea_dict(params.get('ssgc'), 'zgqklx'),
               'ss_qkcd': tools.nullablea_dict(params.get('ssgc'), 'qksfsl'),
               'ss_qksl': tools.nullablea_dict(params.get('ssgc'), 'qksfsl'),
               'ss_ysqk': tools.nullablea_dict(params.get('ssgc'), 'ysxz'),
               'ss_ysl': tools.nullablea_dict(params.get('ssgc'), 'ysl'),
               'ss_trysqk': tools.nullablea_dict(params.get('ssgc'), 'teYsxz'),
               'ss_trysl': tools.nullablea_dict(params.get('ssgc'), 'teYsl'),
               'ss_other': tools.nullablea_dict(params.get('ssgc'), 'qt'),
               'ss_trmc': tools.nullablea_dict(params.get('ssgc'), 'temc'),
               'ss_mcfs': tools.nullablea_dict(params.get('ssgc'), 'mcfs'),
               'ss_mcfw': tools.nullablea_dict(params.get('ssgc'), 'mcfw'),


               'ss_zg': tools.nullablea_dict(params.get('fh'), 'zgfh'),
               'ss_gf': tools.nullablea_dict(params.get('fh'), 'gffh'),
               'ss_fm2': tools.nullablea_dict(params.get('fh'), 'fmfh'),
               'ss_jm': tools.nullablea_dict(params.get('fh'), 'jmfh'),
               'ss_pxzf': tools.nullablea_dict(params.get('fh'), 'fhpxzf'),
               'ss_qa': tools.nullablea_dict(params.get('fh'), 'fhpf'),

                'ss_sfyy': tools.nullablea_dict(params.get('szyy'), 'szsfyy'),
                'ss_gssyy': tools.nullablea_dict(params.get('szyy'), 'sfgss'),
                'ss_gssyyl': tools.nullablea_dict(params.get('szyy'), 'gssyl'),
                'ss_ssyy': tools.nullablea_dict(params.get('szyy'), 'sfqtyy'),
                'ss_qt': tools.nullablea_dict(params.get('szyy'), 'qtyyyl'),

                'gs_sscx': tools.nullablea_dict(params.get('gs'), 'szcx'),
                'gs_sx': tools.nullablea_dict(params.get('gs'), 'sx'),
                'gs_sy': tools.nullablea_dict(params.get('gs'), 'sy'),
                'gs_ssnl': tools.nullablea_dict(params.get('gs'), 'sznl'),
                'gs_gs': tools.nullablea_dict(params.get('gs'), 'gs'),
                'tsqk': tools.nullablea_dict(params.get('qt'), 'tsqk'),
                'record_user': tools.nullablea_dict(params.get('qt'), 'jlzCode'),
                'record_time': tools.nullablea_dict(params.get('qt'), 'jlsj'),
                'hospital_id': 1
            }
            # one2many数据
            o2m_data = []
            #  新生儿
            tes = params.get('te')
            if tes:
                for line in tes:
                    xse_data_ = {
                        'xsr_xb': line['sex'],
                        'xsr_tz': line['weight'],
                        'xsr_sc': line['length'],
                        'xsr_mc_time': line['mcsj'],
                        'xsr_tpblfs': line['tpblfs'],
                        'xsr_sq': line['sfsq'],
                        'xsr_qch': line['qchsfwz'],
                        'xsr_tp_c': line['tpLength'],
                        'xsr_tp_k': line['tpWidth'],
                        'xsr_tp_g': line['tpHeigth'],
                        'xsr_tp_zl': line['tpWeight'],
                        'xsr_tp_fzbw': line['tpfz'],
                        'xsr_tdcd': line['qdLength'],
                        'xsr_rjz': line['qrjzs'],
                        'xsr_ycqk': line['ycqk']
                    }
                    o2m_data.append((0, 0, xse_data_))
            cfqk_data_['record_line'] = o2m_data
            main_id = odoo.env['birth.uterus.record'].create(cfqk_data_)
            create_event = event_type.OperationLogEvent('新增剖宫产手术记录单', 'id:{}'.format(main_id))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {
                'id': main_id
            }, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class OperationRecUpdateAPI(Resource):
    """
    修改剖宫产手术记录单
    :request: put
    :param archivesId: 档案ID
    :param ssjbxx: 手术基本信息
            {
                "ssSj": 手术时
                "csssSj": 出手术室时间
                "ssmc": 手术名称
                "sqzd": 术前诊断
                "sszz": 手术指征
                "shzd": 术后诊断
                "ssz": 手术者
                    {
                        "zdysCode": 主刀医生编码
                        "zdysName": 主刀医生姓名
                        "yzCode": 一助编码
                        "yzName": 一助姓名
                        "ezCode": 二助编码
                        "ezName": 二助姓名
                        "xshsCode": 洗手护士编码
                        "xshsName": 洗手护士姓名
                        "xhhsCode": 巡回护士编码
                        "xhhsName": 巡回护士姓名
                        "mzsCode": 麻醉师编码
                        "mzsName": 麻醉师姓名
                        "jszCode": 接生者编码
                        "jszName": 接生者姓名
                    }
                "mzfs": 麻醉方式
                "mzxg": 麻醉效果
            }
    :param sqjcyzb: 术前检查与准备
            {
                "sqtx": 术前胎心
                "tw": 体位
            }
    :param ssgc: 手术过程
            {
                "ssqklx": 手术切口类型
                "ssqkcd": 手术切口长度
                "ybhqccd": 原疤痕切除长度
                "fmwz": 腹膜位置
                "kfsfsl": 开腹是否顺利
                "tczgwz": 探查子宫位置
                "tczcfj": 探查左侧附件
                "tcycfj": 探查右侧附件
                "zgxdxc": 子宫下段形成
                "sfzl": 是否粘连
                "dkpgfmfz": 打开膀胱腹膜反折
                "zgqklx": 子宫切口类型
                "zgqkcd": 子宫切口长度
                "qksfsl": 切口是否撕裂
                "ysxz": 羊水性状
                "ysl": 羊水量
                "teYsxz": 胎二羊水性状
                "teYsl": 胎二羊水量
            }
    :param xse: 新生儿
            [
                {
                    "id": id
                    "sex": 性别
                    "Weigth": 体重
                    "Length": 身长
                    "mcsj": 娩出时间
                    "tpblfs": 胎盘剥离方式
                    "sfsq": 是否手取
                    "qchsfwz": 取出后是否完整
                    "tpLength": 胎盘长
                    "tpWidth": 胎盘宽
                    "tpHeigth": 胎盘高
                    "tpWeigth": 胎盘重
                    "tpfz": 胎盘附着部位
                    "qdLength": 脐带长度
                    "qrjzs": 脐绕颈周数
                    "ycqk": 异常情况
                }
            ]
    :param fh: 缝合
            {
                "zgfh": 子宫缝合
                "gffh": 关腹缝合
                "fmfh": 缝合-腹膜
                "jmfh": 缝合筋膜
                "fhpxzf": 缝合皮下脂肪
                "fhpf": 缝合皮肤
            }
    :param szyy: 术中用药
            {
                "szsfyy": 术中是否用药
                "gssyl": 宫缩素用量
            }
    :param gs: 宫缩
            {
                "szcx": 术中出血
                "sx": 输血
                "sy": 输液
                "sznl": 术中尿量
                "gs": 宫缩
            }
    :param tsqk: 特殊情况
    :returns: json string:returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def put(self):
        try:
            odoo = OdooManager().get_instance()
            params = request.json
            # 参数校验
            req_params = ['archivesId','ssjbxx','sqjcyzb','ssgc','te','fh','szyy','gs','qt', 'id']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            query_ = [('archives_id', '=', int(params.get('archivesId'))), ('id', '=', int(params.get('id')))]
            # 修改产妇情况
            birth_uterus_record = odoo.env['birth.uterus.record'].search_read(query_)
            if not birth_uterus_record:
                return jsonify({'code': 40005, 'msg': error_code[40005]})
            birth_uterus_record = birth_uterus_record.pop()
            birth_uterus_record_id = birth_uterus_record['id']
            cfqk_data_ = {
               'archives_id': params.get('archivesId'),
               'cf_ts': params.get('ts'),
               'cf_cb': tools.nullablea_dict(params.get('cfqk'), 'cb'),
               'cf_hbz': tools.nullablea_dict(params.get('cfqk'), 'hbz'),
               'cf_hbz_other': tools.nullablea_dict(params.get('cfqk'), 'hbzQt'),
               'cf_bfz': tools.nullablea_dict(params.get('cfqk'), 'bfz'),
               'cf_ccsyc': tools.nullablea_dict(params.get('cfqk'), 'ccsyc'),
               'cf_wzycf': tools.nullablea_dict(params.get('cfqk'), 'wzycf'),

               'ss_create_time': tools.nullablea_dict(params.get('ssjbxx'), 'ssSj'),
               'ss_end_time': tools.nullablea_dict(params.get('ssjbxx'), 'csssSj'),
               'ss_name': tools.nullablea_dict(params.get('ssjbxx'), 'ssmc'),
               'ss_sqzd': tools.nullablea_dict(params.get('ssjbxx'), 'sqzd'),
               'ss_cf_zz': tools.nullablea_dict(params.get('ssjbxx'), 'sszz'),
               'ss_shzd': tools.nullablea_dict(params.get('ssjbxx'), 'shzd'),
               'ss_zd': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['zdysCode'],
               'ss_yz': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['yzCode'],
               'ss_ez': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['ezCode'],
               'ss_sshs': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['xshsCode'],
               'ss_mzfs': tools.nullablea_dict(params.get('ssjbxx'), 'mzfs'),
               'ss_mzxg': tools.nullablea_dict(params.get('ssjbxx'), 'mzxg'),
               'ss_mzs': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['mzsCode'],
               'ss_tsz': tools.nullablea_dict(params.get('ssjbxx'), 'ssz')['jszCode'],


               'ss_sqtx': tools.nullablea_dict(params.get('sqjcyzb'), 'sqtx'),
               'ss_tw': tools.nullablea_dict(params.get('sqjcyzb'), 'tw'),
               'ss_xd': tools.nullablea_dict(params.get('sqjcyzb'), 'xd'),

               'ss_qk': tools.nullablea_dict(params.get('ssgc'), 'ssqklx'),
               'ss_ysbqc': tools.nullablea_dict(params.get('ssgc'), 'ybhqccd'),
               'ss_fm1': tools.nullablea_dict(params.get('ssgc'), 'fmwz'),
               'ss_kf': tools.nullablea_dict(params.get('ssgc'), 'kfsfsl'),
               'ss_zx': tools.nullablea_dict(params.get('ssgc'), 'tczgwz'),
               'ss_sfjzc': tools.nullablea_dict(params.get('ssgc'), 'tczcfj'),
               'ss_sfjyc': tools.nullablea_dict(params.get('ssgc'), 'tcycfj'),
               'ss_zgxdxc': tools.nullablea_dict(params.get('ssgc'), 'zgxdxc'),
               'ss_nl': tools.nullablea_dict(params.get('ssgc'), 'sfzl'),
               'ss_dkpgfm': tools.nullablea_dict(params.get('ssgc'), 'dkpgfmfz'),
               'ss_zgqk': tools.nullablea_dict(params.get('ssgc'), 'zgqklx'),
               'ss_qkcd': tools.nullablea_dict(params.get('ssgc'), 'qksfsl'),
               'ss_qksl': tools.nullablea_dict(params.get('ssgc'), 'qksfsl'),
               'ss_ysqk': tools.nullablea_dict(params.get('ssgc'), 'ysxz'),
               'ss_ysl': tools.nullablea_dict(params.get('ssgc'), 'ysl'),
               'ss_trysqk': tools.nullablea_dict(params.get('ssgc'), 'teYsxz'),
               'ss_trysl': tools.nullablea_dict(params.get('ssgc'), 'teYsl'),
               'ss_other': tools.nullablea_dict(params.get('ssgc'), 'qt'),
               'ss_trmc': tools.nullablea_dict(params.get('ssgc'), 'temc'),
               'ss_mcfs': tools.nullablea_dict(params.get('ssgc'), 'mcfs'),
               'ss_mcfw': tools.nullablea_dict(params.get('ssgc'), 'mcfw'),


               'ss_zg': tools.nullablea_dict(params.get('fh'), 'zgfh'),
               'ss_gf': tools.nullablea_dict(params.get('fh'), 'gffh'),
               'ss_fm2': tools.nullablea_dict(params.get('fh'), 'fmfh'),
               'ss_jm': tools.nullablea_dict(params.get('fh'), 'jmfh'),
               'ss_pxzf': tools.nullablea_dict(params.get('fh'), 'fhpxzf'),
               'ss_qa': tools.nullablea_dict(params.get('fh'), 'fhpf'),

                'ss_sfyy': tools.nullablea_dict(params.get('szyy'), 'szsfyy'),
                'ss_gssyy': tools.nullablea_dict(params.get('szyy'), 'sfgss'),
                'ss_gssyyl': tools.nullablea_dict(params.get('szyy'), 'gssyl'),
                'ss_ssyy': tools.nullablea_dict(params.get('szyy'), 'sfqtyy'),
                'ss_qt': tools.nullablea_dict(params.get('szyy'), 'qtyyyl'),

                'gs_sscx': tools.nullablea_dict(params.get('gs'), 'szcx'),
                'gs_sx': tools.nullablea_dict(params.get('gs'), 'sx'),
                'gs_sy': tools.nullablea_dict(params.get('gs'), 'sy'),
                'gs_ssnl': tools.nullablea_dict(params.get('gs'), 'sznl'),
                'gs_gs': tools.nullablea_dict(params.get('gs'), 'gs'),

                'tsqk': tools.nullablea_dict(params.get('qt'), 'tsqk'),
                'record_user': tools.nullablea_dict(params.get('qt'), 'jlzCode'),
                'record_time': tools.nullablea_dict(params.get('qt'), 'jlsj'),
                'hospital_id': 1
            }
            odoo.env['birth.uterus.record'].write(birth_uterus_record_id, cfqk_data_)
            create_event = event_type.OperationLogEvent('修改剖宫产手术记录单-产妇情况', 'id:{}'.format(birth_uterus_record_id))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            #  新生儿
            odoo.env['birth.uterus.record.line'].unlink(birth_uterus_record['record_line'])
            if  params.get('te'):
                for line in params.get('te'):
                    xse_data_ = {
                        'main_id': birth_uterus_record_id,
                        'xsr_xb': line['sex'],
                        'xsr_tz': line['weight'],
                        'xsr_sc': line['length'],
                        'xsr_mc_time': line['mcsj'],
                        'xsr_tpblfs': line['tpblfs'],
                        'xsr_sq': line['sfsq'],
                        'xsr_qch': line['qchsfwz'],
                        'xsr_tp_c': line['tpLength'],
                        'xsr_tp_k': line['tpWidth'],
                        'xsr_tp_g': line['tpHeigth'],
                        'xsr_tp_zl': line['tpWeight'],
                        'xsr_tp_fzbw': line['tpfz'],
                        'xsr_tdcd': line['qdLength'],
                        'xsr_rjz': line['qrjzs'],
                        'xsr_ycqk': line['ycqk']
                    }
                    odoo.env['birth.uterus.record.line'].create(xse_data_)
            return jsonify({'code': 0, 'msg': 'success', 'data': {}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class OperationRecListAPI(Resource):
    """
    回显剖宫产手术记录单
    :request: get
    :param archivesId: 档案ID
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def get(self):

        try:
            #  参数校验
            params = request.values
            req_params = ['archivesId']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            #  获取产妇情况
            odoo = OdooManager().get_instance()
            #  构造查询条件
            query_ = [('archives_id', '=', int(params.get('archivesId')))]   
            birth_uterus_record_ = odoo.env['birth.uterus.record'].search_read(query_)
            data_ = {
                'te': [],
                'id': None
            }
            #  产妇情况
            if birth_uterus_record_:
                birth_uterus_record_ = birth_uterus_record_.pop()
                data_['id'] = birth_uterus_record_['id']
                #  产妇情况
                data_['cfqk'] = {
                    'yzZ': birth_uterus_record_['cf_yz_week'],
                    'yzT': birth_uterus_record_['cf_yz_day'],
                    'yc': birth_uterus_record_['cf_yc'],
                    'cb': birth_uterus_record_['cf_cb'],
                    'hbz': birth_uterus_record_['cf_hbz'],
                    'hbzQt': birth_uterus_record_['cf_hbz_other'],
                    'bfz': birth_uterus_record_['cf_bfz'],
                    'ccsyc': birth_uterus_record_['cf_ccsyc'],
                    'wzycf': birth_uterus_record_['cf_wzycf'],
                    'ts': birth_uterus_record_['cf_ts']
                }
                #  手术基本信息
                data_['ssjbxx'] = {
                    'ssSj': birth_uterus_record_['ss_create_time'],
                    'csssSj': birth_uterus_record_['ss_end_time'],
                    'ssmc': birth_uterus_record_['ss_name'],
                    'sqzd': birth_uterus_record_['ss_sqzd'],
                    'sszz': birth_uterus_record_['ss_cf_zz'],
                    'shzd': birth_uterus_record_['ss_shzd'],
                    'ssz': {
                        'zdysCode': birth_uterus_record_['ss_zd'][0] if birth_uterus_record_['ss_zd'] else '',
                        'zdysName': birth_uterus_record_['ss_zd'][1] if birth_uterus_record_['ss_zd'] else '',
                        'yzCode': birth_uterus_record_['ss_yz'][0] if birth_uterus_record_['ss_yz'] else '',
                        'yzName': birth_uterus_record_['ss_yz'][1] if birth_uterus_record_['ss_yz'] else '',
                        'ezCode': birth_uterus_record_['ss_ez'][0] if birth_uterus_record_['ss_ez'] else '',
                        'ezName': birth_uterus_record_['ss_ez'][1] if birth_uterus_record_['ss_ez'] else '',
                        'xshsCode': birth_uterus_record_['ss_sshs'][0] if birth_uterus_record_['ss_sshs'] else '',
                        'xshsName': birth_uterus_record_['ss_sshs'][1] if birth_uterus_record_['ss_sshs'] else '',
                        'xhhsCode': '',
                        'xhhsName': '',
                        'mzsCode': birth_uterus_record_['ss_mzs'][0] if birth_uterus_record_['ss_mzs'] else '',
                        'mzsName': birth_uterus_record_['ss_mzs'][1] if birth_uterus_record_['ss_mzs'] else '',
                        'jszCode': birth_uterus_record_['ss_tsz'][0] if birth_uterus_record_['ss_tsz'] else '',
                        'jszName': birth_uterus_record_['ss_tsz'][1] if birth_uterus_record_['ss_tsz'] else ''
                    },
                    'mzfs': birth_uterus_record_['ss_mzfs'],
                    'mzxg': birth_uterus_record_['ss_mzxg']
                }
                #  手术过程
                data_['ssgc'] = {
                    'ssqklx': birth_uterus_record_['ss_qk'],
                    # 'ssqkcd': '',
                    'ybhqccd': birth_uterus_record_['ss_ysbqc'],
                    'fmwz': birth_uterus_record_['ss_fm1'],
                    'kfsfsl': birth_uterus_record_['ss_kf'],
                    'tczgwz': birth_uterus_record_['ss_zx'],
                    'tczcfj': birth_uterus_record_['ss_sfjzc'],
                    'tcycfj': birth_uterus_record_['ss_sfjyc'],
                    'zgxdxc': birth_uterus_record_['ss_zgxdxc'],
                    'sfzl': birth_uterus_record_['ss_nl'],
                    'dkpgfmfz': birth_uterus_record_['ss_dkpgfm'],
                    'zgqklx': birth_uterus_record_['ss_zgqk'],
                    'zgqkcd': birth_uterus_record_['ss_qkcd'],
                    'qksfsl': birth_uterus_record_['ss_qksl'],
                    'ysxz': birth_uterus_record_['ss_ysqk'],
                    'ysl': birth_uterus_record_['ss_ysl'],
                    'teYsxz': birth_uterus_record_['ss_trysqk'],
                    'teYsl': birth_uterus_record_['ss_trysl'],
                    'temc': birth_uterus_record_['ss_trmc'],
                    'mcfs': birth_uterus_record_['ss_mcfs'],
                    'mcfw': birth_uterus_record_['ss_mcfw'],
                    'qt': birth_uterus_record_['ss_other']
                }  
                #  术前检查与准备
                data_['sqjcyzb'] = {
                    'sqtx': birth_uterus_record_['ss_sqtx'],
                    'tw': birth_uterus_record_['ss_tw'],
                    'xd': birth_uterus_record_['ss_xd'],
                }
                #  缝合
                data_['fh'] = {
                    'zgfh': birth_uterus_record_['ss_zg'],
                    'gffh': birth_uterus_record_['ss_gf'],
                    'fmfh': birth_uterus_record_['ss_fm2'],
                    'jmfh': birth_uterus_record_['ss_jm'],
                    'fhpxzf': birth_uterus_record_['ss_pxzf'],
                    'fhpf': birth_uterus_record_['ss_qa']
                }
                #  术中用药
                data_['szyy'] = {
                    'szsfyy': birth_uterus_record_['ss_sfyy'],
                    'sfgss': birth_uterus_record_['ss_gssyy'],
                    'gssyl': birth_uterus_record_['ss_gssyyl'],
                    'sfqtyy': birth_uterus_record_['ss_ssyy'],
                    'qtyyyl': birth_uterus_record_['ss_qt']
                }
                #  宫缩
                data_['gs'] = {    
                    'szcx': birth_uterus_record_['gs_sscx'],
                    'sx': birth_uterus_record_['gs_sx'],
                    'sy': birth_uterus_record_['gs_sy'],
                    'sznl': birth_uterus_record_['gs_ssnl'],
                    'gs': birth_uterus_record_['gs_gs']
                } 
                #  其他
                data_['qt'] = {
                    'tsqk': birth_uterus_record_['tsqk'],
                    'jlzCode': birth_uterus_record_['record_user'][0] if birth_uterus_record_['record_user'] else None,
                    'jlsj': birth_uterus_record_['record_time']
                }   
            #  新生儿
            query_ = [('id', 'in', birth_uterus_record_['record_line'])]
            birth_baby_record_line = odoo.env['birth.uterus.record.line'].search_read(query_)
            if birth_baby_record_line:
                for line_ in birth_baby_record_line:
                    xse_ = {
                        'id': line_['id'],
                        'sex': line_['xsr_xb'],
                        'weight': line_['xsr_tz'],
                        'length': line_['xsr_sc'],
                        'mcsj': line_['xsr_mc_time'],
                        'tpblfs': line_['xsr_tpblfs'],
                        'sfsq': line_['xsr_sq'],
                        'qchsfwz': line_['xsr_qch'],
                        'tpLength': line_['xsr_tp_c'],
                        'tpWidth': line_['xsr_tp_k'],
                        'tpHeigth': line_['xsr_tp_g'],
                        'tpWeight': line_['xsr_tp_zl'],
                        'tpfz': line_['xsr_tp_fzbw'],
                        'qdLength': line_['xsr_tdcd'],
                        'qrjzs': line_['xsr_rjz'],
                        'ycqk': line_['xsr_ycqk']
                    }
                    data_['te'].append(xse_)
            return jsonify({'code': 0, 'msg': 'success', 'data': data_, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})



